package entities;

import game.Collision;
import items.Item;
import items.ItemHolder;

import org.newdawn.slick.Image;

import components.SpriteView;
import components.ViewBasedCollisionModel;

public abstract class ItemEntity extends Entity {
	
	public ItemEntity(Image img) {
		setEntityView(new SpriteView(this, img));
		setCollisionModel(new ViewBasedCollisionModel(this));
	}
	
	public abstract Item getItemInstance(Entity e);
	
	@Override
	public void tick(float dt) {
		super.tick(dt);
		for (Collision<Entity> c : level.getCollisions(this)) {
			Entity e = c.getColldingEntity();
			if (e instanceof ItemHolder) {
				Item item = getItemInstance(e);
				((ItemHolder) e).pickUp(item);
			}
				
		}
	}

}
